package com.lcsw.background.controller;

import com.alibaba.fastjson.JSONObject;
import com.lcsw.background.service.UpdatePayStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息回调
 */
@RestController
public class NotifyUrlController {
    @Autowired
    private UpdatePayStatus updatePayStatus;


    @RequestMapping("/notifyUrl")
    public JSONObject getResult(@RequestBody String jsonString) {
        JSONObject json = null;
        JSONObject object=new JSONObject();
        try {
            json = (JSONObject) JSONObject.parse(jsonString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        updatePayStatus.insertPay(jsonString);  //插入订单记录
        String pay_type = json.get("pay_type").toString();
        if ("0110".equals(pay_type)){//当支付方式为云闪付的时候,修改商户表字段,
            updatePayStatus.updatePayStatus(jsonString);//修改test_merchant_uni的 pay_status
        }
        String result_code = json.get("result_code").toString();
        if ("01".equals(result_code)) {
            object.put("return_code", "01");
            object.put("return_msg", "success");
        } else {
            object.put("return_code", "02");
            object.put("return_msg", "fail");
        }
        return object;
    }
}
